<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>这是home</h1>
    <button onclick="post()">点击发送一个post请求</button>
    <script>
        // 服务器请求在index2.js中

        function post() {
            var xhr = new XMLHttpRequest();
            xhr.open("post","/postOne");
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
            xhr.send("id=10&name=lili"); 
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4){
                    // 接收请求的响应结果(获取响应体内的数据)
                    console.log(xhr.responseText);
                }
            }
            //post请求 [Object: null prototype] { id: '10', name: 'lili' }
        }
    </script>
</body>
</html>